#include <iostream>
#include <map>

using namespace std;

bool search(map<int, int, less<int> > &set, int target)
{
	if (target == 0)
		return true;

	map<int, int,less<int> >::iterator iter;
	for (iter = set.begin(); iter != set.end(); iter++) 
	{
		for (int i = 0; i < (*iter).second; i++) {
			if ((*iter).first <= target) {
				target -= ((*iter).first);
				--((*iter).second);
				if(search(set, target)) {
					return true;
				} else {
					target += ((*iter).first);
					++((*iter).second);
					break;
				}
			} else {
				return false;
			}
		}
	}
	return false;
}

int main(int argc, char* args[])
{
	const int MAX = 100;
	int A[MAX];
	typedef pair<int, int> Int_Pair;
	map<int, int, less<int> > set, copy;
	int n, m;
	scanf("%d %d", &n, &m);
	while (n != 0 && m != 0) {
		int minValue = 100000;
		set.clear();
		copy.clear();

		for (int i = 0; i < n; i++) {
			scanf("%d", A + i);
			if (A[i] < minValue)
				minValue = A[i];
		}
		int c;
		for (int i = 0; i < n; i++) {
			scanf("%d", &c);
			set.insert(Int_Pair(A[i], c));
		}

		int species = 0;
		copy = set;
		for (int i = minValue; i <= m; i++) {
			set = copy;
			if (search(set, i))
				++species;
		}
		printf("%d\n", species);
		scanf("%d %d", &n, &m);
	}
	return 0;
}

